﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>">
	<!-- jsp文件头和头部 -->
	<%@ include file="../admin/top.jsp"%> 
	<style type="text/css">
*{
margin:0;
padding:0;
}
.usertdlabel{
width: 39%;
text-align: right !important; 
}
.usertdval{
width: 59%;
}
.inputVal{
margin-top: 4%;
 }
tr{
width: 100%;
} 
input{
margin-left:4%;
}
.roleName{
padding-left:4% !important;
}
</style>
	</head> 
<body>
<center>
	<form action="user/${msg }.do" name="userForm" id="userForm" method="post">
		<input type="hidden" name="USER_ID" id="user_id" value="${pd.USER_ID }"/>
		<div id="zhongxin" style="width: 99%;">
		<table id="table_report" class="table table-striped table-bordered table-hover">
			
			<input type="hidden" name="ROLE_ID" id="role_id" value="${pd.ROLE_ID }" title="角色"/>
			<tr>
				<td class="usertdlabel">用户名：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="USERNAME" id="loginname" value="${pd.USERNAME }" maxlength="32" readonly title="用户名"/></td>
			</tr>
			<tr>
				<td class="usertdlabel">编号：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="NUMBER" id="NUMBER" value="${pd.NUMBER }" maxlength="32" placeholder="这里输入编号" title="编号" /></td>
			</tr>
			
			<tr>
				<td class="usertdlabel">姓名：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="NAME" id="NAME"  value="${pd.NAME }"  maxlength="32" placeholder="这里输入姓名" title="姓名"/></td>
			</tr>
			<tr>
				<td class="usertdlabel">手机号：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="PHONE" id="PHONE"  value="${pd.PHONE }"  maxlength="32" placeholder="这里输入手机号" title="手机号"/></td>
			</tr>
			<tr>
				<td class="usertdlabel">邮箱：</td>
				<td class="usertdval"><input type="email" class="inputVal" name="EMAIL" id="EMAIL"  value="${pd.EMAIL }" maxlength="32" placeholder="这里输入邮箱" title="邮箱" /></td>
			</tr>
			<tr>
				<td class="usertdlabel">备注：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="BZ" id="BZ" value="${pd.BZ }" placeholder="这里输入备注" maxlength="64" title="备注"/></td>
			</tr>
			<tr>
				<td class="usertdlabel">IP：</td>
				<td class="usertdval"><input type="text" class="inputVal"  name="IP" id="IP" value="${pd.IP }" readonly maxlength="64" title="IP"/></td>
			</tr>
			<tr id="subsysrole">
				<td class="usertdlabel">登录时间：</td>
				<td class="usertdval"><input type="text" class="inputVal" name="LAST_LOGIN" id="LAST_LOGIN" value="${pd.LAST_LOGIN}" readonly maxlength="64" title="登录时间"/></td>
			</tr>
			<tr>
				<td style="text-align: center;" colspan="10">
					<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
				</td>
			</tr>
		</table>
		</div>
		
		<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
		
	</form>

	<!-- PAGE CONTENT ENDS HERE -->
		
		<!-- 返回顶部  -->
		<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
			<i class="icon-double-angle-up icon-only"></i>
		</a>
		
		<!-- 引入 -->
		<script type="text/javascript">
			window.jQuery
					|| document
							.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");
		</script>
		<script src="static/js/bootstrap.min.js"></script>
		<script src="static/js/ace-elements.min.js"></script>
		<script src="static/js/ace.min.js"></script>
		 <!--验证-->
        <script src="<c:url value='plugins/bootstrapvalidator/dist/js/bootstrapValidator.min.js'/>" type="text/javascript"></script>
        <script src="<c:url value='static/js/jquery.validate.min.js'/>" type="text/javascript"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
		<!-- 引入 -->
		
		
		<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
		<script type="text/javascript">
		$(top.hangge());
		 $(function() {
			 showusermenurole();
		
		}); 
		
/*******************************************************展示当前用户能看到的子系统 和角色 Start********************************************************************/		
		 function showusermenurole(){
			 $.ajax({
				 url:'<%=basePath%>user/showusermenurole.do',
				 type:'post',
				 dataType:'json',
				 data : {user_id : $("#user_id").val()},
				 success:function(callback){
					 if(callback.msg=='ok'){
						 var userSysRoles = callback.userSysRole;
						 var html="";
						for(var i = 0;i<userSysRoles.length;i++){
							html+="<tr><td class='usertdlabel'>"+ userSysRoles[i].menu_name+"：</td>";
							html+="<td class='usertdval roleName'>"+userSysRoles[i].role_name+"</td></tr>"
							
						} 
						$("#subsysrole").after(html);
					 }
				 }
			 })
		 }
/*******************************************************展示当前用户能看到的子系统 和角色  End********************************************************************/
		//保存
		function save(){
			/* if($("#role_id").val()==""){
				
				$("#role_id").tips({
					side:3,
		            msg:'选择角色',
		            bg:'#AE81FF',
		            time:2
		        });
				
				$("#role_id").focus();
				return false;
			} */
			if($("#loginname").val()=="" || $("#loginname").val()=="此用户名已存在!"){
				
				$("#loginname").tips({
					side:3,
		            msg:'输入用户名',
		            bg:'#AE81FF',
		            time:2
		        });
				
				$("#loginname").focus();
				$("#loginname").val('');
				$("#loginname").css("background-color","white");
				return false;
			}else{
				$("#loginname").val(jQuery.trim($('#loginname').val()));
			}
			
			if($("#NUMBER").val()==""){
				
				$("#NUMBER").tips({
					side:3,
		            msg:'输入编号',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#NUMBER").focus();
				return false;
			}else{
				$("#NUMBER").val($.trim($("#NUMBER").val()));
			}
			
		
			if($("#NAME").val()==""){
				
				$("#NAME").tips({
					side:3,
		            msg:'输入姓名',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#NAME").focus();
				return false;
			}
			
			var myreg = /^(((13[0-9]{1})|159)+\d{8})$/;
			if($("#PHONE").val()==""){
				
				$("#PHONE").tips({
					side:3,
		            msg:'输入手机号',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#PHONE").focus();
				return false;
			}else if($("#PHONE").val().length != 11 && !myreg.test($("#PHONE").val())){
				$("#PHONE").tips({
					side:3,
		            msg:'手机号格式不正确',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#PHONE").focus();
				return false;
			}
			
			if($("#EMAIL").val()==""){
				
				$("#EMAIL").tips({
					side:3,
		            msg:'输入邮箱',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#EMAIL").focus();
				return false;
			}else if(!ismail($("#EMAIL").val())){
				$("#EMAIL").tips({
					side:3,
		            msg:'邮箱格式不正确',
		            bg:'#AE81FF',
		            time:3
		        });
				$("#EMAIL").focus();
				return false;
			}
			
			if($("#user_id").val()==""){
				hasU();
			}else{
				$("#userForm").submit();
				$("#zhongxin").hide();
				$("#zhongxin2").show();
			}
		}
		
		function ismail(mail){
			return(new RegExp(/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/).test(mail));
			}
		
		//判断用户名是否存在
		function hasU(){
			var USERNAME = $.trim($("#loginname").val());
			$.ajax({
				type: "POST",
				url: '<%=basePath%>user/hasU.do',
		    	data: {USERNAME:USERNAME,tm:new Date().getTime()},
				dataType:'json',
				cache: false,
				success: function(data){
					 if("success" == data.result){
						$("#userForm").submit();
						$("#zhongxin").hide();
						$("#zhongxin2").show();
					 }else{
						$("#loginname").css("background-color","#D16E6C");
						setTimeout("$('#loginname').val('此用户名已存在!')",500);
					 }
				}
			});
		}
		
		//判断邮箱是否存在
		function hasE(USERNAME){
			var EMAIL = $.trim($("#EMAIL").val());
			$.ajax({
				type: "POST",
				url: '<%=basePath%>user/hasE.do',
		    	data: {EMAIL:EMAIL,USERNAME:USERNAME,tm:new Date().getTime()},
				dataType:'json',
				cache: false,
				success: function(data){
					 if("success" == data.result){
						 $("#EMAIL").tips({
								side:3,
					            msg:'邮箱已存在',
					            bg:'#AE81FF',
					            time:3
					        });
						setTimeout("$('#EMAIL').val('')",2000);
					 }
				}
			});
		}
		
		//判断编号是否存在
		function hasN(USERNAME){
			var NUMBER = $.trim($("#NUMBER").val());
			$.ajax({
				type: "POST",
				url: '<%=basePath%>user/hasN.do',
		    	data: {NUMBER:NUMBER,USERNAME:USERNAME,tm:new Date().getTime()},
				dataType:'json',
				cache: false,
				success: function(data){
					 if("success" == data.result){
						 $("#NUMBER").tips({
								side:3,
					            msg:'编号已存在',
					            bg:'#AE81FF',
					            time:3
					        });
						setTimeout("$('#NUMBER').val('')",2000);
					 }
				}
			});
		}
		
	
		
		</script>
	</center>	
	</body>
</html>

